﻿<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">

      <div class="table-page-search-wrapper" v-if="hasPerm('IcRebateProject:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-input v-model="queryParam.code" allow-clear placeholder="请输入"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-input v-model="queryParam.name" allow-clear placeholder="请输入"/>
              </a-form-item>
            </a-col><template v-if="advanced">
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.projectCategory" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.rebateCategory" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.projectId" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.projectCode" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.projectName" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.rebate01" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.rebate02" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.fixedPrice" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.remark" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.field01" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.field02" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.field03" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-date-picker style="width: 100%" placeholder="请选择" v-model="queryParam.startDateDate" @change="onChangestartDate"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-date-picker style="width: 100%" placeholder="请选择" v-model="queryParam.endDateDate" @change="onChangeendDate"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.approvalDescribe" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.registerType" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="">
                  <a-input v-model="queryParam.registerDepartment" allow-clear placeholder="请输入"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="创建时间">
                  <a-date-picker style="width: 100%" placeholder="请选择创建时间" v-model="queryParam.cREATE_DATEDate" @change="onChangecREATE_DATE"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="创建者Id">
                  <a-input v-model="queryParam.cREATE_USER_ID" allow-clear placeholder="请输入创建者Id"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="创建者名称">
                  <a-input v-model="queryParam.cREATE_USER_NAME" allow-clear placeholder="请输入创建者名称"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="更新时间">
                  <a-date-picker style="width: 100%" placeholder="请选择更新时间" v-model="queryParam.mODIFY_DATEDate" @change="onChangemODIFY_DATE"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="修改者Id">
                  <a-input v-model="queryParam.mODIFY_USER_ID" allow-clear placeholder="请输入修改者Id"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="修改者名称">
                  <a-input v-model="queryParam.mODIFY_USER_NAME" allow-clear placeholder="请输入修改者名称"/>
                </a-form-item>
              </a-col><a-col :md="8" :sm="24">
                <a-form-item label="删除时间">
                  <a-date-picker style="width: 100%" placeholder="请选择删除时间" v-model="queryParam.dELETE_DATEDate" @change="onChangedELETE_DATE"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="删除者ID">
                  <a-input v-model="queryParam.dELETE_USER_ID" allow-clear placeholder="请输入删除者ID"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="删除者姓名">
                  <a-input v-model="queryParam.dELETE_USER_NAME" allow-clear placeholder="请输入删除者姓名"/>
                </a-form-item>
              </a-col>            </template>

            <a-col :md="8" :sm="24" >
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px"> {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowKey="(record) => record.iD"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
        <template class="table-operator" slot="operator" v-if="hasPerm('IcRebateProject:add')" >
          <a-button type="primary" v-if="hasPerm('IcRebateProject:add')" icon="plus" @click="$refs.addForm.add()">新增会员营销管理</a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a v-if="hasPerm('IcRebateProject:edit')" @click="$refs.editForm.edit(record)">编辑</a>
          <a-divider type="vertical" v-if="hasPerm('IcRebateProject:edit') & hasPerm('IcRebateProject:delete')"/>
          <a-popconfirm v-if="hasPerm('IcRebateProject:delete')" placement="topRight" title="确认删除？" @confirm="() => IcRebateProjectDelete(record)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </s-table>
      <add-form ref="addForm" @ok="handleOk" />
      <edit-form ref="editForm" @ok="handleOk" />
    </a-card>
  </div>
</template>
<script>
  import { STable } from '@/components'
  import moment from 'moment'
  import { IcRebateProjectPage, IcRebateProjectDelete } from '@/api/modular/main/IcRebateProjectManage'
  import addForm from './addForm.vue'
  import editForm from './editForm.vue'
  export default {
    components: {
      STable,
      addForm,
      editForm
    },
    data () {
      return {
        advanced: false, // 高级搜索 展开/关闭
        queryParam: {},
        columns: [
          {
            title: '',
            align: 'center',
            dataIndex: 'code'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'name'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'projectCategory'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'rebateCategory'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'projectId'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'projectCode'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'projectName'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'rebate01'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'rebate02'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'fixedPrice'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'remark'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'field01'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'field02'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'field03'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'startDate'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'endDate'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'approvalDescribe'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'registerType'
          },
          {
            title: '',
            align: 'center',
            dataIndex: 'registerDepartment'
          },
          {
            title: '创建时间',
            align: 'center',
            dataIndex: 'cREATE_DATE'
          },
          {
            title: '创建者Id',
            align: 'center',
            dataIndex: 'cREATE_USER_ID'
          },
          {
            title: '创建者名称',
            align: 'center',
            dataIndex: 'cREATE_USER_NAME'
          },
          {
            title: '更新时间',
            align: 'center',
            dataIndex: 'mODIFY_DATE'
          },
          {
            title: '修改者Id',
            align: 'center',
            dataIndex: 'mODIFY_USER_ID'
          },
          {
            title: '修改者名称',
            align: 'center',
            dataIndex: 'mODIFY_USER_NAME'
          },
          {
            title: '删除时间',
            align: 'center',
            dataIndex: 'dELETE_DATE'
          },
          {
            title: '删除者ID',
            align: 'center',
            dataIndex: 'dELETE_USER_ID'
          },
          {
            title: '删除者姓名',
            align: 'center',
            dataIndex: 'dELETE_USER_NAME'
          },
          {
            title: '软删除标记',
            align: 'center',
            customRender: (vlaue) => (vlaue ? <a-tag color="green">True</a-tag> : <a-tag color="volcano">False</a-tag>),
            dataIndex: 'iS_DELETED'
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return IcRebateProjectPage(Object.assign(parameter, this.switchingDate())).then((res) => {
            return res.data
          })
        },
        selectedRowKeys: [],
        selectedRows: []
      }
    },
    created () {
      if (this.hasPerm('IcRebateProject:edit') || this.hasPerm('IcRebateProject:delete')) {
        this.columns.push({
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        })
      }
    },
    methods: {
      moment,
      /**
       * 查询参数组装
       */
      switchingDate () {
        const queryParamstartDate = this.queryParam.startDateDate
        if (queryParamstartDate != null) {
            this.queryParam.startDate = moment(queryParamstartDate).format('YYYY-MM-DD')
            if (queryParamstartDate.length < 1) {
                delete this.queryParam.startDate
            }
        }
        const queryParamendDate = this.queryParam.endDateDate
        if (queryParamendDate != null) {
            this.queryParam.endDate = moment(queryParamendDate).format('YYYY-MM-DD')
            if (queryParamendDate.length < 1) {
                delete this.queryParam.endDate
            }
        }
        const queryParamcREATE_DATE = this.queryParam.cREATE_DATEDate
        if (queryParamcREATE_DATE != null) {
            this.queryParam.cREATE_DATE = moment(queryParamcREATE_DATE).format('YYYY-MM-DD')
            if (queryParamcREATE_DATE.length < 1) {
                delete this.queryParam.cREATE_DATE
            }
        }
        const queryParammODIFY_DATE = this.queryParam.mODIFY_DATEDate
        if (queryParammODIFY_DATE != null) {
            this.queryParam.mODIFY_DATE = moment(queryParammODIFY_DATE).format('YYYY-MM-DD')
            if (queryParammODIFY_DATE.length < 1) {
                delete this.queryParam.mODIFY_DATE
            }
        }
        const queryParamdELETE_DATE = this.queryParam.dELETE_DATEDate
        if (queryParamdELETE_DATE != null) {
            this.queryParam.dELETE_DATE = moment(queryParamdELETE_DATE).format('YYYY-MM-DD')
            if (queryParamdELETE_DATE.length < 1) {
                delete this.queryParam.dELETE_DATE
            }
        }
        const obj = JSON.parse(JSON.stringify(this.queryParam))
        return obj
      },
      IcRebateProjectDelete (record) {
        IcRebateProjectDelete(record).then((res) => {
          if (res.success) {
            this.$message.success('删除成功')
            this.$refs.table.refresh()
          } else {
            this.$message.error('删除失败') // + res.message
          }
        })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      onChangestartDate(date, dateString) {
        this.startDateDateString = dateString
      },
      onChangeendDate(date, dateString) {
        this.endDateDateString = dateString
      },
      onChangecREATE_DATE(date, dateString) {
        this.cREATE_DATEDateString = dateString
      },
      onChangemODIFY_DATE(date, dateString) {
        this.mODIFY_DATEDateString = dateString
      },
      onChangedELETE_DATE(date, dateString) {
        this.dELETE_DATEDateString = dateString
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      }
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
